<template>
	<view class="content">
		<view class="banner-box">
			<swiper :autoplay="true" :interval="2000" circular>
				<swiper-item>
					<view class="swiper-item">
						<image src="../../static/banner.jpg" mode="widthFix"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="account">
			<view class="info">
				<image src="/static/shop.png" mode="widthFix">
				</image>
				<view class="name">
					<text style="font-weight: 900;font-size: 16px;">哈尔滨基楚电子科技有限公司</text>
					<br>
					<text style="font-size: 12px;color: gray;">三大运营商授权 官方正品保障</text>
				</view>
			</view>
			<u-grid :border="false" col="4" @click="click" style="margin-top: 20px;">
				<u-grid-item v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex">
					<u-icon :name="baseListItem.name" :size="34" color="#08a0e2"></u-icon>
					<text class="grid-text">{{baseListItem.title}}</text>
					<text class="grid-note">{{baseListItem.note}}</text>
				</u-grid-item>
			</u-grid>
			<u-scroll-list :indicator="false" style="margin-top: 30px;">
				<view v-for="(item, index) in list" :key="index">
					<view class="scroll-list-item">
						<view class="scroll-list-item-box">
							<view class="scroll-list-item-title">
								{{item.title}}
							</view>
							<view class="scroll-list-item-content">
								{{item.content}}
							</view>
						</view>
						<image :src="item.url" mode="aspectFit" class="scroll-list-item-icon">
						</image>
					</view>
				</view>
			</u-scroll-list>
		</view>
		<list :countdown="true" ref="list" style="width: 100%;"></list>

		<!-- 免费领取弹窗 -->
		<u-popup :show="show" mode="center" @close="show = false">
			<view class="pop-box">
				<view style="text-align: center;font-size: 16px;font-weight: bold;margin-bottom: 10px;">
					下单办理
				</view>
				<u--form labelPosition="left" ref="uForm" labelWidth="80">
					<u-form-item label="姓名:" prop="userInfo.name" borderBottom ref="item1">
						<u--input v-model="form.custName" border="none" placeholder="请输入领取人姓名"></u--input>
					</u-form-item>
					<u-form-item label="身份证号:" prop="userInfo.name" borderBottom ref="item2">
						<u--input v-model="form.idNum" maxlength="18" type="idcard" border="none"
							placeholder="请输入领取人身份证号码"></u--input>
					</u-form-item>
					<u-form-item label="联系电话:" prop="userInfo.name" borderBottom ref="item3">
						<u--input v-model="form.phoneNum" maxlength="11" type="number" border="none"
							placeholder="请输入联系电话"></u--input>
					</u-form-item>
					<u-form-item label="详细地址:" prop="userInfo.name" borderBottom ref="item4">
						<u--input v-model="form.custAddress" border="none" placeholder="请输入领取人地址"></u--input>
					</u-form-item>
				</u--form>
				<view class="pop-btn" @click="clickSubmit">
					免费领取
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				form: {
					custName: "",
					idNum: "",
					phoneNum: "",
					custAddress: ""
				},
				list: [{
					title: "生活缴费",
					content: "您的生活管家",
					url: "../../static/jf.png"
				}, {
					title: "视频会员",
					content: "热播好剧随心看",
					url: "../../static/hy.png"
				}, {
					title: "宽带服务",
					content: "网速快如开挂",
					url: "../../static/kd.png"
				}],
				baseList: [{
						name: 'search',
						title: '一证通查',
						note: "名下电话卡数"
					},
					{
						name: 'file-text',
						title: '订单查询',
						note: "查询订单"
					},
					{
						name: 'chat',
						title: '在线客服',
						note: "解决售后问题"
					},
					{
						name: 'share',
						title: '分享店铺',
						note: "终身号卡服务"
					}
				]
			}
		},
		computed: {
			redPack() {
				return this.$store.state.redPack
			}
		},
		onReachBottom() {
			this.$refs.list.reachBottom();
		},
		onLoad() {
			uni.hideTabBar()

			uni.$on("NOTIFICATION_ProductDetail", ((res) => {
				if (res.id == 0) {
					uni.navigateTo({
						url: "/pages/cardDetail/cardDetail"
					})
				} else {
					this.show = true;
				}
			}))

		},
		onUnload() {
			uni.$off("NOTIFICATION_ProductDetail")
		},
		methods: {
			clickSubmit() {

				if (this.form.custName.length <= 0) {
					uni.showToast({
						title: "请输入领取人姓名!",
						icon: "none"
					})
					return;
				}
				if (this.form.idNum.length != 18) {
					uni.showToast({
						title: "身份证号码长度不足18位!",
						icon: "none"
					})
					return;
				}
				if (this.form.phoneNum.length <= 0) {
					uni.showToast({
						title: "请输入联系电话!",
						icon: "none"
					})
					return;
				}
				let res1 = /^(?:(?:\+|00)86)?1\d{10}$/;
				console.log(res1.test(this.form.phoneNum));
				if (res1.test(this.form.phoneNum) == false) {
					uni.showToast({
						title: "手机号格式错误!",
						icon: "none"
					})
					return;
				}
				if (this.form.custAddress.length <= 0) {
					uni.showToast({
						title: "请输入领取人地址!",
						icon: "none"
					})
					return;
				}

				// const baseURL = "http://118.195.148.124:18091"; // 生产 pro_gdapp_h5
				const baseURL = "http://118.195.148.124:8080"; //  pro_gdapp_h5


				uni.request({
					url: baseURL + "/yewu/YwTempOrder/add",
					data: this.form,
					method: "POST",
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: "领取成功!",
							icon: "success"
						})
						this.show = false;
					},
					fail: (err) => {
						console.warn(err);
					}
				})

			},
			go(str) {
				this.$uniGo('switchTab', {
					url: "/pages/user-center/user-center"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pop-box {
		background-color: white;
		width: 300px;
		padding: 30px 20px;
		border-radius: 10px;
		overflow: hidden;

		.pop-btn {
			width: 200px;
			height: 40px;
			line-height: 40px;
			text-align: center;
			margin-left: calc(50% - 100px);
			background-color: #08a0e2;
			color: white;
			font-size: 16px;
			font-weight: bold;
			border-radius: 20px;
			margin-top: 30px;
		}


	}


	@keyframes pop-btn {
		from {
			background-color: #ff0;
		}

		50% {
			background-color: #f00;
		}

		to {
			background-color: #ff0;
		}
	}

	@-webkit-keyframes pop-btn {
		from {
			background-color: #ff0;
		}

		50% {
			background-color: #f00;
		}

		to {
			background-color: #ff0;
		}
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.banner-box {
		width: 100%;
		height: 350rpx;

		swiper {
			width: 100%;
			height: 100%;
		}

		image {
			width: 100vw;
			height: 100%;
		}
	}

	.account {
		width: 95vw;
		margin: 0 auto;
		border-radius: 20rpx;
		padding: 20px 10px;
		background: rgba(255, 255, 255, 1);
		// box-shadow: 0 -2px 8px 0 rgba(0, 0, 0, .1);
		position: relative;
		top: -20px;
		box-sizing: border-box;

		.scroll-list-item {
			width: 150px;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			margin-left: 5px;

			.scroll-list-item-box {
				height: 40px;
				display: flex;
				align-items: center;
				flex-direction: column;
				justify-content: flex-start;
				width: 90px;
			}

			.scroll-list-item-title {
				font-size: 14px;
				font-weight: 600;
				color: #333;
				text-align: left;
				width: 100%;
				height: 20px;
				line-height: 20px;
			}

			.scroll-list-item-content {
				font-size: 12px;
				color: #999;
				text-align: left;
				width: 100%;
			}

			.scroll-list-item-icon {
				width: 40px;
				height: 40px;
				margin-right: 10px;
			}
		}


		.info {
			display: flex;
			align-items: center;
			justify-content: space-between;

			image {
				width: 88rpx;
				height: 88rpx;
				border-radius: 88rpx;
			}

			.name {
				flex: 1;
				margin: 0 20rpx;
			}

			.sum {
				display: flex;
				align-items: center;
				font-weight: bold;

				text {
					color: $theme-color;
					font-size: 38rpx;
					margin-right: 10rpx;
				}
			}

			.img {
				width: 60rpx;
				height: 60rpx;
				background-color: rgba(207, 25, 42, .3);
				border-radius: 60rpx;
			}
		}

		.tips-box {
			display: flex;
			align-items: center;
			font-size: $uni-font-size-sm;
			padding-top: 20rpx;

			.label {
				padding: 0 10rpx;
				color: $theme-color ;
				border: 1rpx solid $theme-color;
				border-radius: 8rpx;
				margin-right: 20rpx;
			}

			.txt {}
		}

		.grid-text {
			color: #333;
			font-size: 14px;
			font-weight: 550;
			line-height: 20px;
			height: 20px;
		}

		.grid-note {
			color: #999;
			font-size: 12px;
		}
	}
</style>